package com.hanamaki.demo03;

import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.Set;

/**
 * 1. selenium中  Cookies信息
 */
public class SeleniumTemplate02 {

    //注册驱动
    /**
     * driver代表浏览器对象
     */
    WebDriver driver;
    @BeforeMethod
    public void setUp() {
        //注册本地火狐打开的位置
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        //初始化
        driver = new FirefoxDriver();
    }

    @Test
    public void test() {
        driver.get("https://www.baidu.com");

        Set<Cookie>cookies=driver.manage().getCookies();
        Cookie[]allCookies=new Cookie[cookies.size()];
        cookies.toArray(allCookies);
        //打印已有的cookie数量和内容
        System.out.println("当前cookie集合的数量为:"+cookies.size());
        System.out.println("");
        for(int i=0;i<allCookies.length;i++){
            System.out.println("第"+(i+1)+"个cookies的各项属性为：");
            System.out.println("cookies名称    -"+allCookies[i].getName());
            System.out.println("cookies值    -"+allCookies[i].getValue());
            System.out.println("cookies所在域    -"+allCookies[i].getDomain());
            System.out.println("cookies路径    -"+allCookies[i].getPath());
            System.out.println("cookies过期时间    -"+allCookies[i].getExpiry());
            System.out.println("");
        }


    }


    @AfterClass
    public void close() {
//        driver.quit();
    }
}
